package com.itfreer.gis.data.server;

import java.util.List;

import org.locationtech.jts.geom.Geometry;
import org.opengis.feature.simple.SimpleFeature;
import org.springframework.stereotype.Component;

import com.itfreer.gis.data.server.arcgis.ArcgisWFSSearch;
import com.itfreer.gis.data.server.arcgis.ArcgisWMSSearch;
import com.itfreer.gis.data.server.geoserver.GeoserverWFSSearch;
import com.itfreer.gis.data.server.geoserver.GeoserverWMSSearch;

/**
 * 定义基于地图数据服务的数据查询操作 目前支持arcgis wms, wfs和geoserver wms，wfs
 */
@Component
public class SpatialSearchServerImp implements SpatialSearchServer {

	private ArcgisWFSSearch arcgisWFSSearch;
	private ArcgisWMSSearch arcgisWMSSearch;
	private GeoserverWFSSearch geoserverWFSSearch;
	private GeoserverWMSSearch geoserverWMSSearch;

	public SpatialSearchServerImp() {
		arcgisWFSSearch = new ArcgisWFSSearch();
		arcgisWMSSearch = new ArcgisWMSSearch();
		geoserverWFSSearch = new GeoserverWFSSearch();
		geoserverWMSSearch = new GeoserverWMSSearch();
	}

	/**
	 * 空间查询，与当关要素空间叠加关系查询
	 * 
	 * @param type
	 *            地图类型
	 * @param url
	 *            地址
	 * @param geometry
	 *            空间要素
	 * @param paras
	 *            参数
	 * @return
	 */
	@Override
	public List<SimpleFeature> queryFeature(String type, String url, Geometry geometry, SearchPara paras)
			throws Exception {
		if (type == null) {
			return null;
		}
		if (type.equals("11")) {
			return arcgisWMSSearch.queryFeature(url, geometry, paras);
		} else if (type.equals("13")) {
			return arcgisWFSSearch.queryFeature(url, geometry, paras);
		} else if (type.equals("21")) {
			return geoserverWMSSearch.queryFeature(url, geometry, paras);
		} else if (type.equals("23")) {
			return geoserverWFSSearch.queryFeature(url, geometry, paras);
		}
		return null;
	}

	/**
	 * 空间查询，查询当前地图范围内地要素
	 * 
	 * @param type
	 *            地图类型
	 * @param url
	 *            地址
	 * @param extent
	 *            当前地图范围
	 * @param paras
	 *            参数
	 * @return
	 */
	@Override
	public List<SimpleFeature> queryFeature(String type, String url, String extent, SearchPara paras) throws Exception {
		if (type == null) {
			return null;
		}
		if (type.equals("11")) {
			return arcgisWMSSearch.queryFeature(url, extent, paras);
		} else if (type.equals("13")) {
			return arcgisWFSSearch.queryFeature(url, extent, paras);
		} else if (type.equals("21")) {
			return geoserverWMSSearch.queryFeature(url, extent, paras);
		} else if (type.equals("23")) {
			return geoserverWFSSearch.queryFeature(url, extent, paras);
		}
		return null;
	}

	/**
	 * 属性查询，根据属性条件进行查询
	 * 
	 * @param type
	 *            地图类型
	 * @param url
	 *            地址
	 * @param where
	 *            属性条件
	 * @param extent
	 *            当前地图范围
	 * @param paras
	 *            参数
	 * @return
	 */
	@Override
	public List<SimpleFeature> queryFeature(String type, String url, String where, String extent, SearchPara paras)
			throws Exception {
		if (type == null) {
			return null;
		}
		if (type.equals("11")) {
			return arcgisWMSSearch.queryFeature(url, where, extent, paras);
		} else if (type.equals("13")) {
			return arcgisWFSSearch.queryFeature(url, where, extent, paras);
		} else if (type.equals("21")) {
			return geoserverWMSSearch.queryFeature(url, where, extent, paras);
		} else if (type.equals("23")) {
			return geoserverWFSSearch.queryFeature(url, where, extent, paras);
		}
		return null;
	}

}
